const install =(Vue,vm)=>{
	const isLogin = ()=>{
		const token = uni.getStorageSync('access_token');
		//console.log(getCurrentPages());
		if(!token){
			//先记录来源页面
			const currentPage = getCurrentPages().pop();
			const {options,route} = currentPage;
			const optionsKeys = Object.keys(options); //将options里面的所有键取出来，以数组的形式返回
			//console.log(optionsKeys);
			let params = '';
			if(optionsKeys.length){
				//说明有参数
				params = optionsKeys.reduce((pre,current)=>{
					if(current.length){
						return pre + current + '=' + options[current] + '&';
					}
					else{
						return pre;
					}
				},'?').slice(0,-1);
			}
			console.log(params);
			//还需要保存页面本身的参数
			uni.setStorageSync('backUrl',route + params);
			uni.$u.toast('请登录后访问本页面');
			//跳转到登录页面
			setTimeout(()=>{
				uni.$u.route({
					type:'redirect',
					url:'/pages/auth/login'
				})
			},1500)
			return false;
		}
		return true;
	}
	vm.$u.utils = {
		isLogin
	}
}
export default{
	install
}